<?php

/**
 * traitement actions.
 *
 * @package    app_clinique
 * @subpackage traitement
 * @author     Your name here
 * @version    SVN: $Id: actions.class.php 2288 2006-10-02 15:22:13Z fabien $
 */
class traitementActions extends autotraitementActions
{
    public function executeCreateTraitement(){

         $this->sf_traitement = $this->getsfTraitementOrCreate();
         $this->idconsultation = $this->getRequestParameter('idconsultation');
         $this->sf_consultation = sfConsultationPeer::retrieveByPk($this->idconsultation);

         if ($this->getRequest()->getMethod() == sfRequest::POST){

                $this->updatesfTraitementFromRequest();
                $this->savesfTraitement($this->sf_traitement);
                $this->setFlash('notice', 'Vos modifications ont été enregistrées');

                return $this->redirect('traitement/show?idconsultation='.$this->sf_traitement->getsfConsultation()->getId());

         }
         else
         {
              $this->labels = $this->getLabels();
         }
    }
    
    public function executeShow(){
        $this->idconsultation = $this->getRequestParameter('idconsultation');
        $this->sf_consultation = sfConsultationPeer::retrieveByPk($this->idconsultation);
        //liste des traitements pour la consultation transmise en parametre
        $c = new Criteria();
        $c->add(sfTraitementPeer::CONSULTATION_ID, $this->idconsultation);
        $this->listeTraitements = sfTraitementPeer::doselect($c);

    }

    public function handleErrorCreateTraitement()
  {
    $this->preExecute();
    $this->sf_traitement = $this->getsfTraitementOrCreate();
    $this->updatesfTraitementFromRequest();

    $this->labels = $this->getLabels();
    $this->redirect('traitement/createTraitement?erreur=1&idconsultation='.$this->sf_traitement->getConsultationId());
  }

  public function executeEdit()
  {
    $this->sf_traitement = $this->getsfTraitementOrCreate();

    if ($this->getRequest()->getMethod() == sfRequest::POST)
    {
      $this->updatesfTraitementFromRequest();

      $this->savesfTraitement($this->sf_traitement);

      $this->setFlash('notice', "L'enregistrement a été effectué");

      if ($this->getRequestParameter('save_and_add'))
      {
        return $this->redirect('traitement/create');
      }
      else if ($this->getRequestParameter('save_and_list'))
      {
        return $this->redirect('traitement/list');
      }
      else
      {
        return $this->redirect('traitement/edit?id='.$this->sf_traitement->getId());
      }
    }
    else
    {
      $this->labels = $this->getLabels();
    }
  }
}
